home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2000 July / macformat-092.iso / Fireworks 3 / Settings / Commands / Panel Layout....jsf < prev   
Encoding:
Text File  |  1999-11-19  |  3.2 KB  |  127 lines

  1.  
  2. // Copyright (c) 1998, 1999 Macromedia. All rights reserved.
  3.  
  4. fw.checkFwJsVersion(0);
  5.  
  6. function enquote(str)
  7. {
  8.     if (str == null)
  9.         return "null";
  10.  
  11.     return "\"" + str.toString() + "\"";
  12. }
  13.  
  14. function determineQuadrant(pos)
  15. {
  16.     var screen = fw.screenRect;
  17.     var ldelta = pos.left - screen.left;
  18.     var rdelta = screen.right - pos.right;
  19.     var tdelta = pos.top - screen.top;
  20.     var bdelta = screen.bottom - pos.bottom;
  21.     if (ldelta < rdelta) {
  22.         // left-hand side
  23.         if (tdelta < bdelta) {
  24.             // top-left quadrant
  25.             return 0;        
  26.         } else {
  27.             // bottom-left quadrant
  28.             return 1;        
  29.         }
  30.     } else {
  31.         // right-hand side
  32.         if (tdelta < bdelta) {
  33.             // top-right quadrant
  34.             return 2;        
  35.         } else {
  36.             // bottom-right quadrant
  37.             return 3;        
  38.         }
  39.     }
  40. }
  41.  
  42. function getAnchorPointForQuadrant(quadrant)
  43. {
  44.     var anchor = null;
  45.     var screen = fw.screenRect;
  46.     switch (quadrant) {
  47.         case 0:    anchor = { x: screen.left, y: screen.top }; break;
  48.         case 1:    anchor = { x: screen.left, y: screen.bottom }; break;
  49.         case 2:    anchor = { x: screen.right, y: screen.top }; break;
  50.         case 3:    anchor = { x: screen.right, y: screen.bottom }; break;
  51.     }
  52.     return anchor;
  53. }
  54.  
  55. function toRelativePos(quadrant, pos)
  56. {
  57.     var anchor = getAnchorPointForQuadrant(quadrant);
  58.     var npos = { left: pos.left - anchor.x, right: pos.right - anchor.x, top: pos.top - anchor.y, bottom: pos.bottom - anchor.y };
  59.     return npos;
  60. }
  61.  
  62. function fromRelativePos(quadrant, pos)
  63. {
  64.     var anchor = getAnchorPointForQuadrant(quadrant);    
  65.     var npos = { left: pos.left + anchor.x, right: pos.right + anchor.x, top: pos.top + anchor.y, bottom: pos.bottom + anchor.y };
  66.     return npos;
  67. }
  68.  
  69. function setRelativeFloaterPosition(tabname, quadrant, pos)
  70. {
  71.     var npos = fromRelativePos(quadrant, pos);
  72.     fw.setFloaterPosition(tabname, npos);
  73. }
  74.  
  75. var jscode = "";
  76.  
  77. jscode += getAnchorPointForQuadrant.toSource();
  78. jscode += fromRelativePos.toSource();
  79. jscode += setRelativeFloaterPosition.toSource();
  80.  
  81. var floaters = fw.getFloaterGroupings();
  82. jscode += "//" + floaters.toSource() + "\n";
  83. for (i in floaters) {
  84.     var tabsInCurFloater = floaters[i];
  85.     
  86.     // first, get the groupings right
  87.     var anyVisible = false;
  88.     var mainTabName = null;
  89.     var visibleTabName = null;
  90.     for (j in tabsInCurFloater) {
  91.         var tabName = tabsInCurFloater[j];
  92.  
  93.         if (fw.getFloaterVisibility(tabName))
  94.             visibleTabName = tabName;
  95.  
  96.         jscode += "fw.setFloaterGrouping(" + enquote(tabName) + ", " + enquote(mainTabName) + ");";
  97.         jscode += "\n";
  98.  
  99.         if (mainTabName == null)
  100.             mainTabName = tabName;
  101.     }
  102.  
  103.     if (visibleTabName != null) {
  104.         jscode += "fw.setFloaterVisibility(" + enquote(visibleTabName) + ", true);";
  105.         jscode += "\n";
  106.     } else {
  107.         jscode += "fw.setFloaterVisibility(" + enquote(mainTabName) + ", false);";
  108.         jscode += "\n";
  109.     }
  110.     
  111.     var abspos = fw.getFloaterPosition(mainTabName);
  112.     var quadrant = determineQuadrant(abspos);
  113.     var relpos = toRelativePos(quadrant, abspos);
  114.     jscode += "setRelativeFloaterPosition(" + enquote(mainTabName) + ", " + quadrant + ", " + relpos.toSource() + ");";    
  115.     jscode += "\n";
  116.  
  117.     jscode += "\n";
  118. }
  119.  
  120. var filename = prompt("Name your panel layout. Saved panel layouts display in the Commands menu.");
  121. if (filename != null) {
  122.     var destDir = App.appJsCommandsDir + "/Panel Layout Sets";
  123.     if (!Files.exists(destDir))
  124.         Files.createDirectory(destDir);
  125.     fw.saveJsCommand(jscode, destDir + "/" + filename);
  126. }
  127.